Regular Expressions

DiskState uses regular expression (regexp) in many places. These expressions may seem pretty difficult at first, but they shall prove themselves highly powerful once you learn to use them. Regular expressions are commonly used in the Perl and Tcl language (from the Unix world).

We will describe the special characters of Regexp and conclude with a few examples.

New to this?

If you are not used to regular expression, the first thing you will probably notice is the use of .* instead of the normal *. The dot before the asterisk means that it will match any character. Combined with the asterisk gives match any character zero or more times. With the power of regular expressions, one could use s* to match zero or more of the letter s. It might be a bit unusual at first, but regular expressions are very powerful.

Character Description

 ^
Matches beginning of string. For example, "^F", will match an "F" only at the beginning of the string.

 ^
A caret "^" immediately following a left-bracket ( [ ) excludes the remaining characters within the brackets. [^0-9] matches non-digits only.

 $
Dollar sign ($) matches the end of the string. "abc$" will match sub-string "abc" only if it is at the end of the string.

 |
Alternation character ( | ) allows either expression on its side to match target string. "a|b" will match "a" as well as "b".

 .
The dot ( . ) matches any character.

 *
Asterisk (*) means that the character to the left should match 0 or more times.

 +
Similar as asterisk (*), but requires at least one match (1 or more times).

 ?
Question mark (?) matches the left character 0 or 1 times.

 [ ]
Brackets enclosing a set of characters indicates that any of the enclosed characters may match the target character.

 \
Indicates special character, like the "." with "\.", "?" as "\?", brackets etc.

Popular Regexps in DiskState

Regular Expression Meaning
.*backup.* Finds any text with the substring backup in it. Example: SrcBackupFile.tmp
File[0-9]+\.tmp$ Looks for any filename beginning with the four letters File, followed by at least any number, and ending with the file extension tmp.
.*\.exe$ The very analogous *.exe searches one can do. Note the backslash to avoid the special character dot, as well as the $-sign at the end to match end of string (extensions are always at the end).